package com.visionblue.business.ship.page.outer

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import com.flyco.tablayout.SegmentTabLayout
import com.flyco.tablayout.listener.OnTabSelectListener
import com.visionblue.business.ship.R
import com.visionblue.business.ship.base.BaseActivity
import com.visionblue.business.ship.base.BaseVMActivity
import com.visionblue.business.ship.page.orders.OrderActivity
import com.visionblue.business.ship.page.orders.OrdersApplyFragment
import com.visionblue.business.ship.page.orders.OrdersReceiveFragment
import kotlinx.android.synthetic.main.activity_choose_out_object.*
import kotlinx.android.synthetic.main.activity_orders.*
import kotlinx.android.synthetic.main.activity_orders.fl_back
import org.koin.androidx.viewmodel.ext.android.getViewModel

/**
 * @author: ysj
 * @date : 2021/5/2014:17
 * desc:选择转出对象
 */
class ChooseOutObjectActivity: BaseActivity() {
    private var imgBack:ImageView?= null
    private var segmentTabLayout: SegmentTabLayout?=null
    private val mTitles = arrayOf("岸上存储点", "污染物运输公司")
    private var mFragments:ArrayList<Fragment>?=null

    override val layoutId: Int
        get() = R.layout.activity_choose_out_object

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        imgBack = findViewById(R.id.img_back)
        this.imgBack!!.setOnClickListener{
            finish()
        }


        segmentTabLayout = findViewById(R.id.stlTabLayout)
        segmentTabLayout!!.setTabData(mTitles)

        mFragments = ArrayList()

        mFragments!!.add(
            PortStoreFragment()
        )
        mFragments!!.add(
            TransCompanyFragment()
            //PdfViewFragment()
        )

        val mViewPagerAdapter = MyPagerAdapter(supportFragmentManager, mFragments!!)

        mineViewPager.adapter = mViewPagerAdapter


        //滑动、点击切换页面
        stlTabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                mineViewPager.currentItem = position
            }

            override fun onTabReselect(position: Int) {}
        })


        //滑动、点击切换页面
        mineViewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(i: Int, v: Float, i1: Int) {}
            override fun onPageSelected(i: Int) {
                stlTabLayout.currentTab = i
            }

            override fun onPageScrollStateChanged(i: Int) {}
        })

    }


    companion object {
        fun start(context: Context) {
            Intent(context, ChooseOutObjectActivity::class.java)
                .run {
                    context.startActivity(this)
                }
        }
    }

    class MyPagerAdapter(fm: FragmentManager, var fragments: ArrayList<Fragment>) : FragmentPagerAdapter(fm) {
        override fun getItem(position: Int): Fragment {
            return fragments[position]
        }

        override fun getCount(): Int {
            return fragments.size
        }
    }
}